package cn.Alibaba.pet.controller;

import cn.Alibaba.pet.service.IPetOnlineAuditLogService;
import cn.Alibaba.pet.domain.PetOnlineAuditLog;
import cn.Alibaba.pet.query.PetOnlineAuditLogQuery;
import cn.Alibaba.basic.util.JsonResult;
import cn.Alibaba.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
* 后端接口类；
*/
@RestController
@RequestMapping("/petOnlineAuditLog")
public class PetOnlineAuditLogController {

    @Autowired
    public IPetOnlineAuditLogService petOnlineAuditLogService;

    /**
     * 接口：添加或修改
     * @param petOnlineAuditLog  传递的实体
     * @return JsonResult 响应给前端
     */
    @PutMapping
    public JsonResult addOrUpdate(@RequestBody PetOnlineAuditLog petOnlineAuditLog){
        try {
            if( petOnlineAuditLog.getId()!=null)
                petOnlineAuditLogService.update(petOnlineAuditLog);
            else
                petOnlineAuditLogService.save(petOnlineAuditLog);
            return JsonResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me().setMsg("操作失败");
        }
    }

    /**
    * 接口：删除
    * @param id
    * @return JsonResult 响应给前端
    */
    @DeleteMapping(value="/{id}")
    public JsonResult delete(@PathVariable("id") Long id){
        try {
            petOnlineAuditLogService.del(id);
            return JsonResult.me();
        } catch (Exception e) {
        e.printStackTrace();
            return JsonResult.me().setMsg("删除失败");
        }
    }

    /**
    * 接口：批量删除
    * @param ids
    * @return JsonResult 响应给前端
    */
    @PatchMapping
    public JsonResult patchDelete(@RequestBody List<Long> ids){
        try {
                petOnlineAuditLogService.PatchDel(ids);
            return JsonResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me().setMsg("批量删除失败");
        }
    }

    /**
    * 接口：查询单个对象
    * @param id
    */
    @GetMapping("/{id}")
    public PetOnlineAuditLog findOne(@PathVariable("id")Long id) {
        return petOnlineAuditLogService.findOne(id);
    }


    /**
    * 接口：查询所有
    * @return
    */
    @GetMapping
    public List<PetOnlineAuditLog> findAll(){
        return petOnlineAuditLogService.findAll();
    }


   /**
    * 接口：分页查询或高级查询
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping
    public PageList<PetOnlineAuditLog> queryPage(@RequestBody PetOnlineAuditLogQuery query) {
        return petOnlineAuditLogService.queryPage(query);
    }
}
